package com.topn;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

// 分组比较器
public class TGroupComparator extends WritableComparator {


    public TGroupComparator() {
        super(Tkey.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        Tkey k1 = (Tkey) a;
        Tkey k2 = (Tkey) b;

        // 相同的年、月分到一组
        if (k1.getYear() == k2.getYear() && k1.getMonth() == k2.getMonth()) {
            // 是一组数据
            return 0;
        } else {
            // 不是一组
            return 1;
        }

    }
}
